package com.example.rwq_test.ThreadPool.affinity;

//import net.openhft.affinity.AffinityStrategies;
//import net.openhft.affinity.AffinityThreadFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadPoolExecutor;

public class AffinityThreadFactory {

    private static final Map<ThreadPoolTypeEnum, ThreadPoolExecutor> threadPoolExecutorMap = new HashMap<>();

    static {
        //清扫任务控制相关任务
//        threadPoolExecutorMap.put(ThreadPoolTypeEnum.TASK_MODULE, new ThreadPoolExecutor(
//                3, 3, 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(1000),
//                new AffinityThreadFactory("taskControlModule", AffinityStrategies.SAME_CORE, AffinityStrategies.DIFFERENT_CORE, AffinityStrategies.ANY), new ThreadPoolExecutor.AbortPolicy()));

    }

    public static void submit(ThreadPoolTypeEnum threadPoolTypeEnum, Runnable runnable) {
        ThreadPoolExecutor threadPoolExecutor = threadPoolExecutorMap.get(threadPoolTypeEnum);
        if (threadPoolExecutor == null) {
            threadPoolExecutorMap.get(ThreadPoolTypeEnum.OTHER_MODULE).execute(runnable);
        } else {
            threadPoolExecutor.execute(runnable);
        }
    }

}